package org.app.counter
{
	import com.reider.log4AS3.Logger;
	import com.reider.log4AS3.LoggerFactory;
	
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	public class SampleCounter
	{
		private static var log:Logger = LoggerFactory.getLogger(SampleCounter)
		private var timer:Timer
		
		public function SampleCounter()
		{
			timer = new Timer(1000, 5)
			timer.addEventListener(TimerEvent.TIMER, onTimer)
			timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete)
			
			log.debug("Created timer: {}", timer)
		}
		
		public function start():void
		{
			log.info("Starting Timer")
			timer.reset()
			timer.start()
		}
		
		private function onTimer(event:TimerEvent):void
		{
			log.debug("Timer fired {} times out of {}", timer.currentCount, timer.repeatCount, timer)
			
			if(timer.currentCount > timer.repeatCount-2){
				log.warn("Timer limit: {} almost reached", timer.repeatCount)
			}
		}
		
		private function onTimerComplete(event:TimerEvent):void
		{
			log.info("Timer finished")
			//start()
		}

	}
}